<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Open a new connection to the MySQL server</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysqlnduhconnection.close.html">MysqlndUhConnection::close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysqlnduhconnection.construct.html">MysqlndUhConnection::__construct</a></div>
 <div class="up"><a href="class.mysqlnduhconnection.html">MysqlndUhConnection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mysqlnduhconnection.connect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MysqlndUhConnection::connect</h1>
  <p class="verinfo">(PECL mysqlnd-uh &gt;= 1.0.0-alpha)</p><p class="refpurpose"><span class="refname">MysqlndUhConnection::connect</span> &mdash; <span class="dc-title">Open a new connection to the MySQL server</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mysqlnduhconnection.connect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>MysqlndUhConnection::connect</strong></span>
    ( <span class="methodparam"><span class="type"><span class="type mysqlnd_connection">mysqlnd_connection</span></span> <code class="parameter">$connection</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$use&quot;</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$database</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$socket</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$mysql_flags</code></span>
   )</div>

  <p class="para rdfs-comment">
   Open a new connection to the MySQL server.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-mysqlnduhconnection.connect-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<em><code class="parameter">connection</code></em></dt>

    <dd>

     <p class="para">
      Mysqlnd connection handle. Do not modify!
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">host</code></em></dt>

    <dd>

     <p class="para">
       Can be either a host name or an IP address. Passing the NULL value or
       the string &quot;localhost&quot; to this parameter,
       the local host is assumed. When possible, pipes will be used
       instead of the TCP/IP protocol.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">user</code></em></dt>

    <dd>

     <p class="para">
      The MySQL user name.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">password</code></em></dt>

    <dd>

     <p class="para">
      If not provided or <strong><code>NULL</code></strong>,
      the MySQL server will attempt to authenticate
      the user against those user records which have no password only.
      This allows one username to be used with different permissions
      (depending on if a password as provided or not).
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">database</code></em></dt>

    <dd>

     <p class="para">
      If provided will specify the default database to be used when performing queries.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">port</code></em></dt>

    <dd>

     <p class="para">
      Specifies the port number to attempt to connect to the MySQL server.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">socket</code></em></dt>

    <dd>

     <p class="para">
      Specifies the socket or named pipe that should be used.
      If <strong><code>NULL</code></strong>, mysqlnd will default to
      <em>/tmp/mysql.sock</em>.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">mysql_flags</code></em></dt>

    <dd>

     <p class="para">
      Connection options.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-mysqlnduhconnection.connect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> on success.
   Otherwise, returns <strong><code>FALSE</code></strong>
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mysqlnduhconnection.connect-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1852">
    <p><strong>Example #1 <span class="function"><strong>MysqlndUhConnection::connect()</strong></span> example</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">proxy&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">MysqlndUhConnection&nbsp;</span><span style="color: #007700">{<br />&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$host</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$passwd</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$port</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$socket</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysql_flags</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s(%s)\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">__METHOD__</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">parent</span><span style="color: #007700">::</span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$host</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$passwd</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$port</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$socket</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysql_flags</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s&nbsp;returns&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">__METHOD__</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$ret</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$ret</span><span style="color: #007700">;<br />&nbsp;}<br />}<br /></span><span style="color: #0000BB">mysqlnd_uh_set_connection_proxy</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">proxy</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
proxy::connect(array (
  0 =&gt; NULL,
  1 =&gt; &#039;localhost&#039;,
  2 =&gt; &#039;root&#039;,
  3 =&gt; &#039;&#039;,
  4 =&gt; &#039;test&#039;,
  5 =&gt; 3306,
  6 =&gt; NULL,
  7 =&gt; 131072,
))
proxy::connect returns true
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-mysqlnduhconnection.connect-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">
     <span class="function"><a href="function.mysqlnd-uh-set-connection-proxy.html" class="function" rel="rdfs-seeAlso">mysqlnd_uh_set_connection_proxy()</a> - Installs a proxy for mysqlnd connections</span>
    </li>
    <li class="member">
     <span class="function"><a href="function.mysqli-connect.html" class="function" rel="rdfs-seeAlso">mysqli_connect()</a> - 别名 mysqli::__construct</span>
    </li>
    <li class="member">
     <span class="function"><a href="function.mysql-connect.html" class="function" rel="rdfs-seeAlso">mysql_connect()</a> - 打开一个到 MySQL 服务器的连接</span>
    </li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysqlnduhconnection.close.html">MysqlndUhConnection::close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysqlnduhconnection.construct.html">MysqlndUhConnection::__construct</a></div>
 <div class="up"><a href="class.mysqlnduhconnection.html">MysqlndUhConnection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
